<?php

/*

Search (search.pro.php)

*/
ob_start();
$x = 0;

$command[1] = ereg_replace(" ","",$command[1]);

$search = mysql_query("SELECT username,display_name,id FROM members2 WHERE rank > '1' AND game = '$game' ORDER BY username");
while ($fetchSearch = mysql_fetch_array($search))
{
	$id = $fetchSearch[id];
	$simuPTS[$id] = similar_text($command[1], $fetchSearch[username], $simPTS[$id]);
	if ($simPTS[$id] >= 80)
	{
		$fetchSearch[username] = badwords($fetchSearch[username]);
		$fetchSearch[display_name] = badwords($fetchSearch[display_name]);

		$x++;
		$goTo = "profile";
		$profile = $fetchSearch[username];
		$searchResults .= "User: <a 		href=user_profile.php?game=$game&user=$fetchSearch[username]>$fetchSearch[display_name]</a><br>";
	}
}

$search2 = mysql_query("SELECT id,name FROM user_pets2 WHERE game = '$game' ORDER BY name");
while ($fetchSearch2 = mysql_fetch_array($search2))
{
	$id = $fetchSearch2[id];
	$simuPTS[$id] = similar_text($command[1], $fetchSearch2[name], $simPTS[$id]);
	if ($simPTS[$id] >= 80)
	{
		$fetchSearch2[name] = badwords($fetchSearch2[name]);
		$x++;
		$goTo = "pet";
		$petID = $fetchSearch2[id];
		$searchResults .= "Pet: <a 		href=user_pets.php?game=$game&id=$fetchSearch2[id]>$fetchSearch2[name]</a><br>";
	}
}

if ($x == "0")
{
	$searchResults = "No results were found.";
}

if ($x == "1")
{
	if ($goTo == "profile")
	{
		header("Location: $base_url/user_profile.php?game=$game&user=$profile");
	}

	if ($goTo == "pet")
	{
		header("Location: $base_url/user_pets.php?game=$game&id=$petID");
	}
}

if ($x != "1")
{
	print "$openHTML$searchResults$closeHTML";
}

?>